<?php defined('DM_PATH') or die('DIRECT ACCESS IS NOT ALLOWED');

class Dm_Gcontroller extends Controller {
	
	/* {public} */
	public $layout = 'layout';
	public $module = 'default';
	    
	/* {actions} */
	public function indexAction()
	{
		$this->loadAction();
	}
	
	public function loadAction()
	{
		$this->disableRender = true;
		
		if ($this->getParam("key"))
		{
			$nodeId = (int)$this->getParam("key");
			
			$node = DM_Tree::getNode($nodeId);
			
			$guiController = ucfirst($this->module).'_Controller_Gui_'.ucfirst($node['tree_type']);
			$gui = new $guiController($node);
			
			$gui->generateGuis($guiController);
		}
	}
	
	protected function generateGuis($guiController)
	{
		$classMethods = get_class_methods($guiController);
		
		$i = 0;
		foreach ($classMethods as $methodName) {
			if (strpos($methodName, 'GUI') !== false)
			{
				echo '<div class="gui-block" id="'.substr($methodName, 0, -3).'" '.($i == 0 ? 'style="display: block"' : 'style="display: none"').'>'.$guiController::$methodName().'</div>';
				
				$i++;
			}
		}
	}
}